package cn.haut.online_read.controller.crawler.zhuishushenqi;

import cn.haut.online_read.crawler.RankingListBookCrawler;
import cn.haut.online_read.crawler.RankingListHotSearchUrlCrawler;
import cn.haut.online_read.utils.CrawlerUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author xing
 * @date 2021-05-04 20:18
 */
@Controller("rankingListController")
@RequestMapping(value = "/ranking")
public class RankingListController {

    public static final String BASE_URL_RANKING = "http://zhuishushenqi.com/ranking";

    @GetMapping(value = "")
    @ResponseBody
    public String getRanking() {
        String url = BASE_URL_RANKING;
        return CrawlerUtils.getJsonResult(new RankingListHotSearchUrlCrawler(), url);
    }

    /**
     * 返回 排行榜页面的 书籍信息
     *
     * @param rankingId 排行榜 id
     * @param type 类型
     * @return
     */
    @GetMapping(value = "/{rankingId}")
    @ResponseBody
    public String getRankingBookInfo (
            @PathVariable("rankingId") String rankingId,
            @RequestParam("type") String type
    ) {
        // http://zhuishushenqi.com/ranking/[rankingID]?type=[type]
        String url = String.format("%s/%s?type=%s", BASE_URL_RANKING, rankingId, type);
        return CrawlerUtils.getJsonResult(new RankingListBookCrawler(), url);
    }
}
